﻿<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Article.aspx.cs" Inherits="IP_PROJECT.Article" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <asp:Repeater ID="ArticleRepeater" runat="server" DataSourceID="ArticleDataSource">
         <ItemTemplate>
             <asp:LoginView ID="EditView" runat="server">
                 <RoleGroups>
                    <asp:RoleGroup Roles="Admin">
                        <ContentTemplate>
                            <p>
                                <asp:Button ID="SaveArticle" runat="server" Text="Save" OnClick="SaveArticle_Click" CommandArgument='<%# Eval("Id") %>' />
                                <asp:Button ID="DeleteArticle" runat="server" Text="Delete" OnClick="DeleteArticle_Click" CommandArgument='<%# Eval("Id") %>' />
                            </p>
                            <p>
                                <b>Title</b>
                                <asp:TextBox ID="ArticleTitle" runat="server" Text='<%# Eval("Title") %>' MaxLength="50" />
                            </p>
                            <b>Description:</b>
                            <p>
                                <asp:TextBox ID="ArticleDescription" runat="server" Text='<%# Eval("Description") %>' TextMode="MultiLine" MaxLength="500" />
                            </p>
                            <b>Content:</b>
                            <p>
                                <asp:TextBox ID="ArticleContent" runat="server" Text='<%# Eval("Content") %>' TextMode="MultiLine" />
                            </p>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="General">
                        <ContentTemplate>
                            <h3><%# Eval("Title") %></h3>
                            <p><%# Eval("Content") %></p>
                        </ContentTemplate>
                    </asp:RoleGroup>
                 </RoleGroups>
                 <AnonymousTemplate>
                    <h3><%# Eval("Title") %></h3>
                    <p><%# Eval("Content") %></p>
                 </AnonymousTemplate>
             </asp:LoginView>
         </ItemTemplate>
    </asp:Repeater>
    <asp:SqlDataSource ID="ArticleDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT [Id], [Title], [Description], [Content] FROM [Articles] WHERE ([Id] = @Id)">
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="Id" Name="Id" Type="Int32"></asp:QueryStringParameter>
        </SelectParameters>
    </asp:SqlDataSource>
    <h1>Comments:</h1>
    <asp:Repeater ID="CommentsRepeater" runat="server" DataSourceID="CommentsDataSource">
        <ItemTemplate>
            <p>
                <asp:LoginView ID="AdminView" runat="server" ViewStateMode="Enabled">
                    <RoleGroups>
                        <asp:RoleGroup Roles="Admin">
                            <ContentTemplate>
                                <asp:Button ID="DeleteComment" runat="server" Text="x" CommandArgument='<%# Eval("Id") %>' OnClick="DeleteComment_Click" />
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
                </asp:LoginView>
                <b><%# Eval("Nickname") %>:</b> <i>"<%# Eval("Content") %>"</i>
            </p>
        </ItemTemplate>
    </asp:Repeater>
    <asp:SqlDataSource runat="server" ID="CommentsDataSource" ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' SelectCommand="SELECT [Id], [Content], [Nickname] FROM [Comments] WHERE ([Article] = @Article)">
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="Id" Name="Article" Type="Int32"></asp:QueryStringParameter>
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:LoginView ID="LoginView" runat="server" ViewStateMode="Enabled">
        <LoggedInTemplate>
            <b>Comment: </b>
            <asp:TextBox ID="CommentInput" runat="server"/>
            <asp:Button ID="Submit" runat="server" Text="Submit" OnClick="Submit_Click" />
        </LoggedInTemplate>
        <AnonymousTemplate>
           To write comments you have to <a href="Account/Login.aspx">Log in</a>
        </AnonymousTemplate>
   </asp:LoginView>
</asp:Content>
